package com.jsbb.controller.sys;

import com.jsbb.common.Message;
import com.jsbb.common.PageVo;
import com.jsbb.dto.sys.SysRoleQueryDto;
import com.jsbb.dto.sys.SysRoleAddDto;
import com.jsbb.dto.sys.SysRoleUpdateDto;
import com.jsbb.service.sys.SysRoleService;
import com.jsbb.vo.sys.SysRoleDetailVo;
import com.jsbb.vo.sys.SysRoleListVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 角色管理Controller
 *
 * @author jsbb
 */
@RestController
@RequestMapping("/sys/role")
@Tag(name = "1.2 系统管理-角色管理")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    @PostMapping("/all")
    @Operation(summary = "获取列表，不分页")
    public Message<List<SysRoleListVo>> all() {
        List<SysRoleListVo> list = sysRoleService.selectAll();
        return Message.success(list);
    }

    @PostMapping("/list")
    @Operation(summary = "获取列表")
    public Message<PageVo<SysRoleListVo>> list(@Validated @RequestBody SysRoleQueryDto sysRoleQueryDto) {
        PageVo<SysRoleListVo> pageVo = sysRoleService.list(sysRoleQueryDto);
        return Message.success(pageVo);
    }

    @GetMapping("/get/{id}")
    @Operation(summary = "获取详情")
    @Parameter(name = "id", description = "ID")
    public Message<SysRoleDetailVo> get(@PathVariable("id") Long id) {
        SysRoleDetailVo sysRoleDetailVo = sysRoleService.get(id);
        return Message.success(sysRoleDetailVo);
    }

    @PostMapping("/add")
    @Operation(summary = "新增")
    public Message add(@Validated @RequestBody SysRoleAddDto addDto) {
        sysRoleService.add(addDto);
        return Message.success();
    }

    @PostMapping("/update")
    @Operation(summary = "修改")
    public Message update(@Validated @RequestBody SysRoleUpdateDto updateDto) {
        sysRoleService.update(updateDto);
        return Message.success();
    }

    @PostMapping("/delete/{id}")
    @Operation(summary = "删除")
    @Parameter(name = "id", description = "ID")
    public Message delete(@PathVariable("id") Long id) {
        sysRoleService.delete(id);
        return Message.success();
    }
}
